<?php

/**
 * This is the model class for table "userlog".
 *
 * The followings are the available columns in table 'userlog':
 * @property integer $id
 * @property string $userid
 * @property string $id_member
 * @property string $id_card
 * @property string $a_head_t
 * @property string $f_name
 * @property string $l_name
 * @property string $a_head_e
 * @property string $f_name_e
 * @property string $l_name_e
 * @property string $user_sex
 * @property string $address
 * @property string $phone
 * @property string $i_email
 * @property string $x_email
 * @property string $date_inwork
 * @property string $position
 * @property string $departid
 * @property string $userlog
 * @property string $passlog
 * @property integer $worktime
 * @property string $status
 * @property string $send_letter
 * @property string $active_works
 * @property string $type_emp
 */
class Userlog extends CActiveRecord {

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'userlog';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(

            array('userid, id_member ,id_card , a_head_t , f_name ,l_name, a_head_e, f_name_e, l_name_e , user_sex, address, phone ,i_email ,date_inwork , position ,departid , worktime , status , send_letter, active_works, type_emp, userlog, passlog',    'required'),
            // array('userid,a_head_t', 'required'),
            // array('userid,worktime', 'numerical', 'integerOnly' => true),
            array('id_member', 'length', 'max' => 8),
            array('phone', 'length', 'max' => 11),
            array('id_card', 'length', 'max' => 13),
            array('userlog, passlog', 'length', 'max' => 20),
            array('a_head_t, a_head_e, user_sex', 'length', 'max' => 15),
            array('f_name, l_name, f_name_e, l_name_e, phone, i_email, x_email, position', 'length', 'max' => 100),
            array('status', 'length', 'max' => 13),
            array('active_works, type_emp', 'length', 'max' => 9),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('id, userid, id_member, id_card, a_head_t, f_name, l_name, a_head_e, f_name_e, l_name_e, user_sex, address, phone, i_email, x_email, date_inwork, position, departid, userlog, passlog, worktime, status, send_letter, active_works, type_emp', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            "depart" => array(self::BELONGS_TO, "Departs", "departid"));
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'รหัสพนักงาน',
            'userid' => 'ยูเซอร์ไอดี',
            'id_member' => 'Id Member',
            'id_card' => 'Id Card',
            'a_head_t' => 'คำนำหน้า',
            'f_name' => 'ชื่อ',
            'l_name' => 'นามสกุล',
            'a_head_e' => 'prefix',
            'f_name_e' => 'Name',
            'l_name_e' => 'SerName',
            'user_sex' => 'เพศ',
            'address' => 'ที่อยู่',
            'phone' => 'Tel.',
            'i_email' => 'เมลล์ใน',
            'x_email' => 'เมลล์นอก',
            'date_inwork' => 'วันที่เริ่มทำงาน',
            'position' => 'ตำแหน่ง',
            'departid' => 'แผนก',
            'userlog' => 'Username',
            'passlog' => 'Password',
            'worktime' => 'Worktime',
            'status' => 'ระดับ',
            'send_letter' => 'Send Letter',
            'active_works' => 'Active Works',
            'type_emp' => 'Type Emp',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('userid', $this->userid, true);
        $criteria->compare('id_member', $this->id_member, true);
        $criteria->compare('id_card', $this->id_card, true);
        $criteria->compare('a_head_t', $this->a_head_t, true);
        $criteria->compare('f_name', $this->f_name, true);
        $criteria->compare('l_name', $this->l_name, true);
        $criteria->compare('a_head_e', $this->a_head_e, true);
        $criteria->compare('f_name_e', $this->f_name_e, true);
        $criteria->compare('l_name_e', $this->l_name_e, true);
        $criteria->compare('user_sex', $this->user_sex, true);
        $criteria->compare('address', $this->address, true);
        $criteria->compare('phone', $this->phone, true);
        $criteria->compare('i_email', $this->i_email, true);
        $criteria->compare('x_email', $this->x_email, true);
        $criteria->compare('date_inwork', $this->date_inwork, true);
        $criteria->compare('position', $this->position, true);
        $criteria->compare('departid', $this->departid, true);
        $criteria->compare('userlog', $this->userlog, true);
        $criteria->compare('passlog', $this->passlog, true);
        $criteria->compare('worktime', $this->worktime);
        $criteria->compare('status', $this->status, true);
        $criteria->compare('send_letter', $this->send_letter, true);
        $criteria->compare('active_works', $this->active_works, true);
        $criteria->compare('type_emp', $this->type_emp, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return Userlog the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public static function listTypeEmpTha() {
        $data = array(
            "นาย" => "นาย",
            "นางสาว" => "นางสาว",
            "นาง" => "นาง",
        );
        return $data;
    }

    public static function listTypeEmpEng() {
        $data = array(
            "Mr." => "Mr.",
            "Ms." => "Ms.",
            "Mrs." => "Mrs.",
        );
        return $data;
    }

    public static function listTypeEmpSex() {
        $data = array(
            "ชาย" => "ชาย",
            "หญิง" => "หญิง",
        );
        return $data;
    }

    public static function listTypeEmpStatus() {
        $data = array(
            "Administrator" => "Administrator",
            "Manager" => "Manager",
            "Supervisor" => "Supervisor",
            "Personnel" => "Personnel",
            "Director" => "Director",
        );
        return $data;
    }

    public static function listTypeEmpLetter() {
        $data = array(
            "supervisor" => "supervisor",
            "Manager" => "Manager",
            "director" => "director",
            "Personnel" => "Personnel",
            "boss" => "boss",
        );
        return $data;
    }

    public static function listTypeEmpWorks() {
        $data = array(
            "working" => "working",
            "unworking" => "unworking",
        );
        return $data;
    }

    public static function listTypeEmpType() {
        $data = array(
            "station" => "station",
            "daily" => "daily",
            "probation" => "probation",
        );
        return $data;
    }

     public static function listDepart() {
         $data = array(
          "2" => "การเงิน/บัญชี",
	"3" =>	"การตลาด Food",
	"4" =>	"จัดซื้อ",
	"5" =>	"ซ่อมบำรุง",
	"7" =>	"เทคโนโลยีสารสนเทศ",
	"8" =>	"ผลิต",
	"9" =>	"ผลิตภัณฑ์",
	"10" =>	"บริการลูกค้า",
	"11" =>	"คลังสินค้า",
	"12" => "จัดส่งสินค้า",
	"13" =>  "ควบคุมคุณภาพ",
	"14" => "พัฒนาผลิตภัณฑ์",
	"15" => "บุคคล",
	"31" => "จัดซื้อต่างประเทศ2",
	"17" => "ผู้บริหาร",
	"19" => "การตลาด Cosmetic",
	"20" => "ผู้ดูแลระบบ",
	"30" => "จัดซื้อต่างประเทศ1",
	"25" => "การตลาด Pharma",
	"29" => "จัดซื้อในประเทศ",
	"28" => "การตลาดFood C",
	"32" => "บัญชีต้นทุน",
	"33" => "บัญชีบริหาร",
	"34" => "บัญชีการเงิน"
        );
        return $data;
    
}

}
